<template>
  <div class="download">
    <!-- currentPage: 1, // 当前页码
      pageSize: 5, // 每页的数据条数 -->
    <el-table
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      height="500"
      border
      style="width: 100%"
    >
      <el-table-column prop="filename" label="文件名称" width="180">
      </el-table-column>

      <el-table-column prop="score" label="成绩" width="180"> </el-table-column>
      <el-table-column prop="time" label="提交时间"> 
        <template slot-scope="scope">
         {{moment(scope.row.time).format('YYYY年MM月DD日 HH:mm')}}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="tableData">
          <a
            :href="`http://localhost:8081/v1/students/download/${tableData.row.filename}`"
            target="_blank"
            >下载文件</a
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页器 -->
    <div class="block" style="margin-top: 15px">
      <el-pagination
        align="center"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[1, 5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.length"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import { Message } from "element-ui";
export default {
  data() {
    return {
      tableData: [], //设初始值
      currentPage: 1, // 当前页码
      total: 20, // 总条数
      pageSize: 5, // 每页的数据条数
    };
  },
  mounted() {
    axios
      .get("/v1/students/download")
      .then((result) => {
        // console.log(result.data);
        if (result.data.status == 200) {
          this.tableData = result.data.data;
        } else {
          Message.error({
            showClose: true,
            message: "没有模拟考试数据，请多多练习",
            type: "error",
          });
        }
      })
      .catch((err) => {
        console.log(err);
      });
  },
  methods: {
    //当选择每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.currentPage = 1; //从第一页开始显示
      this.pageSize = val;
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
  },
};
</script>
<style lang="scss">
.download {
  margin: 0 auto;
  margin-top: 50px;
  a {
    text-decoration: none;
    font-size: 16px;
  }
}
</style>